package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC162 {

    public int findPeakElement(int[] arr) {
        if (arr.length <= 1) {
            return 0;
        }

        int left = Integer.MIN_VALUE, right = Integer.MIN_VALUE;
        for (int i = 0; i < arr.length; i++) {
            if (i > 0) {
                left = arr[i - 1];
            }

            if (i == arr.length - 1) {
                right = Integer.MIN_VALUE;
            } else {
                right = arr[i + 1];
            }


            if (arr[i] > left && arr[i] > right) {
                return i;
            }
        }

        return 0;
    }


    public static void main(String[] args) {
        LC162 an = new LC162();
        int[] arr = InputUtil.toIntegerArray("[3,2,1]");
        System.out.println(an.findPeakElement(arr));
    }
}
